(function __simplepage3(){
	var pageId = "simplepage";
	
	var queryModelName = pageId+'.queryform.data';
	var mainModelName  = pageId+'.maingrid.data';
	
	Ext.define( queryModelName , {
        extend: 'Ext.data.Model',
        fields: ['userCode', 'userName',"aliasName","address","startTime","endTime","birthday"]
    });
    
	Ext.define(pageId+'.maingrid.data', {
        extend: 'Ext.data.Model',
        fields: ['userCode', 'userName',"aliasName","address",
        {name:"userCode",type:'string'},
        {name:"userName",type:'string'},
        {name:"aliasName",type:'string'},
        {name:"address",type:'string'},
        {name:"startTime",type:'date',dateFormat:'Y-m-d'},
        {name:"endTime",type:'date',dateFormat:'Y-m-d'},
        {name:"birthday",type:'date',dateFormat:'Y-m-d'},
        ]
    });
    
    var mainStore = Ext.create('Ext.data.JsonStore', {
		model : mainModelName,
		proxy:{
			type: 'ajax',
	        url: 'Acus/acus/loadGridData.shtml',
	        reader: {
	            type: 'json',
	            root: 'rows',
	            idProperty: 'userCode'
	        }
		}
	});
	
	
	Ext.define("Ext.ux.MyRowEditing",{
		extend:"Ext.grid.plugin.RowEditing",
		// private
	    validateEdit: function() {
	        var me             = this,
	            editor         = me.editor,
	            context        = me.context,
	            record         = context.record,
	            newValues      = {},
	            originalValues = {},
	            editors        = editor.items.items,
	            e,
	            eLen           = editors.length,
	            name, item;
	
	        for (e = 0; e < eLen; e++) {
	            item = editors[e];
	            name = item.name;
	
	            newValues[name]      = item.getValue();
	            originalValues[name] = record.get(name);
	        }
	
	        Ext.apply(context, {
	            newValues      : newValues,
	            originalValues : originalValues
	        });
			return me.fireEvent('validateedit', me, context) !== false && !context.cancel;
//					        return me.callParent(arguments) && me.getEditor().completeEdit();
	    }
	});
    
	return {
		getPageId:function(){
			return pageId;
		},
		layout:{
			type:'vbox',
			padding: 1 ,
			align:'stretch'
		},
		items:[
			{
				xtype:'form',
				frame:true,
				layout: {
	                type:'table',
	                columns:3
	            },
	            defaults:{
	            	margin:5 
	            },
	            waitMsgTarget:true,
	            reader: Ext.create('Ext.data.reader.Json', {
		            successProperty: 'success',
		            root:'data',
		            model:queryModelName
		        }),
	            tbar: {
	                xtype: 'toolbar',
	                defaults:{
	                	minWidth:40
	                },
	                items: [
	                	{itemId: 'query', text: '查询',handler:function(){
//	                		var form = this.up('form').getForm();
//	                		form.submit({
//	                			url:'/Acus/acus/loadData.shtml',
//	                			submitEmptyText: true,
//	                    		waitMsg: 'Saving Data...',
//	                    		waitTitle:'器'
//	                		});
	                		var form = this.up('form').getForm();
	                		mainStore.reload({
	                			params:form.getValues()
	                		});
	                		
	                	}},
	                	{itemId: 'Load', text: 'Load',handler:function(){
	                		var form = this.up('form').getForm();
	                		form.load({
	                			url:'/Acus/acus/loadData.shtml',
	                			waitMsg: 'Loading Data...',
	                    		waitTitle:'器'
	                		});
	                	}},
	                	{itemId: 'add', text: '新增'},
	                	{itemId: 'save', text: '保存'},
	                	{itemId: 'delete', text: '删除'}
	                ]
	            },
				items:[
					{ xtype:'numberfield'  , name:'userCode' , fieldLabel : '用户代码' ,width: 250 , labelWidth:80},
					{ xtype:'textfield'  , name:'userName' , fieldLabel : '用户姓名',width: 250 , labelWidth:80},
					{ xtype:'textfield'  , name:'aliasName' , fieldLabel : '别名',width: 250 , labelWidth:80},
					{ xtype:'textfield'  , name:'address' , fieldLabel : '地址',width: 250 , labelWidth:80},
					{ xtype:'datefield'  , name:'startTime' , fieldLabel : '起始时间',width: 250 , labelWidth:80},
					{ xtype:'datefield'  , name:'endTime' , fieldLabel : '结束时间',width: 250 , labelWidth:80},
					{ xtype:'datefield'  , name:'birthday' , fieldLabel : '生日',width: 250 , labelWidth:80}
				]
			},
			{
				xtype:'grid',
				//hideHeaders:false,
				//collapsible : true,
				columnLines: true,
				flex:1,
				selModel:Ext.create('Ext.selection.CheckboxModel'),
				columns: [
					{  text:'userCode'  , dataIndex:'userCode' , flex:1 ,editor : 'textfield'},
					{  text:'userName'  , dataIndex:'userName' , flex:1 ,editor : 'textfield'},
					{  text:'aliasName' , dataIndex:'aliasName', flex:1 ,editor : 'textfield'},
					{  text:'address'   , dataIndex:'address'  , flex:1 ,editor : 'textfield'},
					{  text:'startTime' , dataIndex:'startTime', flex:1 ,editor : 'datefield', format:'Y-m-d',renderer: Ext.util.Format.dateRenderer('Y-m-d')},
					{  text:'endTime'   , dataIndex:'endTime'  , flex:1 ,editor : 'datefield',format:'Y-m-d',renderer: Ext.util.Format.dateRenderer('Y-m-d')},
					{  text:'birthday'  , dataIndex:'birthday' , flex:1 ,editor : 'datefield',format:'Y-m-d',renderer: Ext.util.Format.dateRenderer('Y-m-d')} 
				],
				store:mainStore,
				bbar: Ext.create('Ext.PagingToolbar', { store:mainStore  }),
				viewConfig: {
			        stripeRows: true,
			        enableTextSelection: true
			    },
			    plugins:[
			    	Ext.create("Ext.ux.MyRowEditing",{
			    		completeEdit: function() {
					        var me = this;
					        if (me.editing && me.validateEdit()) {
					        	var params = {};
//					        	params.map = {
//					        		name:"name1",
//					        		name2:"name2",
//					        		code:"code"
//					        	};
					        	params["map.name1"]="1233";
					        	params["map.name2"]="2222";
			    				Ext.Ajax.request({
			    					url: '/Acus/acus/saveRow.shtml',
			    					params:params,
								    success: function(response, opts) {
								        var result = Ext.decode(response.responseText);
								        if(result.success){
								        	me.getEditor().completeEdit();
								        }else{
								        	alert(response.responseText);
								        }
//								        alert(response.responseText);
								        //console.dir(obj);
								    }
								});
//					            me.editing = false;
//					            me.fireEvent('edit', me, me.context);
					        }
					    }
			    	})
			    ]
			}
		]
	}
})()





